
let ul=document.querySelector('.main ul')
let uli=document.querySelector('.mobile ul')
let xhr1 =new XMLHttpRequest()
xhr1.open('get','http://chst.vip:1234/api/getbaicaijiatitle',true)
xhr1.onload=function(){
    if(xhr1.status===200){
        let res1 =JSON.parse(xhr1.responseText)
        let an1=res1 .result
        let las=''
        an1.forEach(abc=> {
            las+=`
            <li titleId=${abc.titleId}>${abc.title}</li>
            `   
        });
        uli.innerHTML=las
    }    
}
xhr1.send(null)

let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0',true)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        let lis=''
        an.forEach(item => {
            // console.log(item.productHref.match(/blank\">(\S*)</)[1]);
            lis+=`
            <li>
                ${item.productImg}
                <div class="one">
                    <h4>
                        <span>${item.productName.slice(17,19)}</span>
                        ${item.productName.slice(27)}
                    </h4>
                    <div class="two">
                        <p class="p1">${item.productPrice.slice(3,5)}</p>
                        <p class="p2">${item.productPrice.slice(13,14)}</p>
                        <p class="p3">${item.productPrice.match(/em>(\S*)<del/)[1]}</p>
                        <del>${item.productPrice.match(/<del>(\S*)</)[1]}</del>
                        <del>￥1000</del>
                    </div>
                    <div class="three" >
                        <p class="p4" style="width:118px">
                        <span>0%</span>
                        <nav class="p6"></nav>
                        </p>
                        <p class="p5">已领<span class="span1">126</span>张/剩余<span class="span2">0</span>张</p>
                    </div>
                    <div class="four">
                    ${item.productCoupon.match(/blank\">(\S*)</)[1]}
                    </div>

                    <div class="five">
                    ${item.productHref.match(/blank\">(\S*)</)[1]}
                    </div>
                </div>       
            </li>    
            ` 
        });
        ul.innerHTML=lis
        let p6=document.querySelectorAll('.main ul li .three .p6')
        let p4=document.querySelector('.main ul li .three .p4')
        let span=document.querySelectorAll('.main ul li .three .p4 span')
        let span1=document.querySelectorAll('.main ul li .three .p5 .span1')
        let span2=document.querySelectorAll('.main ul li .three .p5 .span2')
        let num=0
        let index=0
        let abc=119
        var timer
           timer= setInterval(function fn(){
                num ++;    
                index++
                abc--
                for(var i=0;i<p6.length;i++){
                    p6[i].style.width=num+'px'
                    if(num>p4.style.width.slice(0,-2)){
                        num=p4.style.width.slice(0,-2)
                        clearInterval(timer)
                    }
                }
                for(var j=0;j<span.length;j++){
                    span[j].innerHTML=parseInt((num/p4.style.width.slice(0,-2))*100)+'%'
                    span[j].style.left=num/2.3+'px'
 
                }  
                for(var l=0;l<span1.length;l++){
                    span1[l].innerHTML=index
                    if(index>126){
                        index=126
                    }
                }
                for(var q=0;q<span2.length;q++){
                    span2[q].innerHTML=abc
                    if(abc<0){
                        abc=0
                    }
                }
            }, 50);     
               
    }
}
xhr.send(null)



uli.onclick=function(ev){
var e=ev ||window.event
var target=e.target || e.scrElement
target.style.color='red'
$(target).css('color','red').siblings().css('color','black')

let xhr =new XMLHttpRequest()
xhr.open('get','http://chst.vip:1234/api/getbaicaijiaproduct?titleid='+target.getAttribute('titleId'),true)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        let lis=''
        an.forEach(item => {
            // console.log(item.productHref.match(/blank\">(\S*)</)[1]);
            lis+=`
            <li >
                ${item.productImg}
                <div class="one">
                    <h4>
                        <span>${item.productName.slice(17,19)}</span>
                        ${item.productName.slice(27)}
                    </h4>
                    
                    <div class="two">
                        <p class="p1">${item.productPrice.slice(3,5)}</p>
                        <p class="p2">${item.productPrice.slice(13,14)}</p>
                        <p class="p3">${item.productPrice.match(/em>(\S*)<del/)[1]}</p>
                        <del>${item.productPrice.match(/<del>(\S*)</)[1]}</del>
                        <del>￥1000</del>
                    </div>

                    <div class="three">
                            <p class="p4" style="width:118px">
                            <span>0%</span>
                            <nav class="p6"></nav>
                            </p>
                        <p class="p5">已领<span class="span1">126</span>张/剩余<span class="span2">0</span>张</p>
                    </div>

                    <div class="four">
                    ${item.productCoupon.match(/blank\">(\S*)</)[1]}
                    </div>

                    <div class="five">
                    ${item.productHref.match(/blank\">(\S*)</)[1]}
                    </div>

                </div>       
            </li>
                
            `
            
        });
        ul.innerHTML=lis
        let p6=document.querySelectorAll('.main ul li .three .p6')
        let p4=document.querySelector('.main ul li .three .p4')
        let span=document.querySelectorAll('.main ul li .three .p4 span')
        let span1=document.querySelectorAll('.main ul li .three .p5 .span1')
        let span2=document.querySelectorAll('.main ul li .three .p5 .span2')
        
        let num=0
        let index=0
        let abc=119
        var timer
           timer= setInterval(function fn(){
                num ++;    
                index++
                abc--
                for(var i=0;i<p6.length;i++){
                    p6[i].style.width=num+'px'
                    if(num>p4.style.width.slice(0,-2)){
                        num=p4.style.width.slice(0,-2)
                        clearInterval(timer)
                    }
                }
                for(var j=0;j<span.length;j++){
                    span[j].innerHTML=parseInt((num/p4.style.width.slice(0,-2))*100)+'%'
                    span[j].style.left=num/2.3+'px'
 
                }  
                for(var l=0;l<span1.length;l++){
                    span1[l].innerHTML=index
                    if(index>126){
                        index=126
                    }
                }
                for(var q=0;q<span2.length;q++){
                    span2[q].innerHTML=abc
                    if(abc<0){
                        abc=0
                    }
                }
            }, 50);

   
    }
}
xhr.send(null)

   
}